﻿var CurrentAd = {};

Ext.onReady(function () {
    PageSafe();

    //未审核广告
    var adstore = new Ext.data.JsonStore({
        url: Ext.getClassUrl('Advertisement.AdvertisementView', 'GetFlowAd'),
        root: 'ResponseObject',
        fields: ['PID', 'GName', 'GUrl', 'GRemark', 'Creater', 'Period', 'NTime', 'SurplusTime', 'GT', 'ChargeUser', 'ChargeUser.UserName', 'TransfS', 'BelongFlow', 'FlowPID', 'FlowID', 'PersonID', 'NodeID', 'ContentID', 'FlowLastUpdate'],
        listeners: {
            beforeload: function (st, op) {
                var re = new JsonRequest();
                re.category = CATEGORY.READONLY;
                st.baseParams = re;
                st.proxy.conn.jsonData = re;
            }
        }
    });
    var adsm = new Ext.grid.CheckboxSelectionModel({
        singleSelect: true,
        listeners: {
            rowselect: function () {
                var k = adgrid.getSelectionModel().selections.items;
                if (k.length > 0) {
                    CurrentAd = k[0].json;
                }
            },
            rowdeselect: function () {
                CurrentAd = {};
            }
        }
    });
    var adgrid = new Ext.grid.GridPanel({
        bodyStyle: 'padding:2px',
        border: false,
        split: true,
        height: 500,
        sm: adsm,
        loadMask: true, //加载
        columns: [
       adsm,
       { id: 'GName', header: '广告名称', width: 130, dataIndex: 'GName', sortable: true },
       { id: 'ChargeUser.UserName', header: '发布人', width: 80, dataIndex: 'ChargeUser.UserName', sortable: true },
       { id: 'GRemark', header: '备注', width: 260, dataIndex: 'GRemark', sortable: true },
       { id: 'Period', header: '有效日期(天)', width: 100, dataIndex: 'Period', sortable: true },
       { id: 'GT', header: '来源', width: 100, dataIndex: 'GT', sortable: true },
        { id: 'TransfS', header: '状态', width: 100, dataIndex: 'TransfS', sortable: true },
       { id: 'SurplusTime', header: '剩余日期(天)', width: 100, dataIndex: 'SurplusTime', sortable: true },
       { id: 'NTime', header: '日期', width: 100, dataIndex: 'NTime', sortable: true }
   ],
        store: adstore
    });


    var page = new Ext.Viewport({
        layout: 'border',
        items: [{
            region: 'center',
            title: '广告流程审核',
            iconCls: 'flow-icon',
            layout: 'border',
            items: [{
                region: 'center',
                style: 'padding:2px',
                title: '等待审核的广告信息',
                items: adgrid
            }, {
                region: 'south',
                title: '审核操作',
                style: 'padding:2px',
                height: 160,
                layout: 'table',
                defaults: {
                    // 对每一个子面板都有效applied to each contained panel
                    style: 'padding:20px'
                },
                layoutConfig: {
                    // 这里指定总列数The total column count must be specified here
                    columns: 2
                },

                items: [{
                    rowspan: 2,
                    xtype: 'textfield',
                    id:'content',
                    height: 60,
                    width: 300
                }, {
                    xtype: 'button',
                    text: '通过',
                    handler: function () {
                        if (CurrentAd.PID == null) { Ext.Msg.alert("提示信息", "请选择需要审核的广告"); return; }
                        var re = new JsonRequest();
                        re.params.info = CurrentAd;
                        re.params.c = Ext.getCmp("content").getValue();
                        Ext.Ajax.request({
                            url: Ext.getClassUrl('Advertisement.AdvertisementView', 'PassFlow'),
                            jsonData: re,
                            success: function (re, op) {
                                var obj = Ext.decode(re.responseText);
                                if (!obj.HasError) {
                                    Ext.Msg.alert("提示信息", "广告审核成功");
                                    adstore.load();
                                }
                                else {
                                    Ext.Msg.alert("提示信息", "广告审核失败，请联系管理员");
                                }
                            }
                        });
                    }
                }, {
                    xtype: 'button',
                    text: '拒绝',
                    handler: function () {
                        if (CurrentAd.PID == null) { Ext.Msg.alert("提示信息", "请选择需要审核的广告"); return; }
                        var re = new JsonRequest();
                        re.params.info = CurrentAd;
                        re.params.c = Ext.getCmp("content").getValue();
                        Ext.Ajax.request({
                            url: Ext.getClassUrl('Advertisement.AdvertisementView', 'RejectFlow'),
                            jsonData: re,
                            success: function (re, op) {
                                var obj = Ext.decode(re.responseText);
                                if (!obj.HasError) {
                                    Ext.Msg.alert("提示信息", "广告审核成功");
                                    adstore.load();
                                }
                                else {
                                    Ext.Msg.alert("提示信息", "广告审核失败，请联系管理员");
                                }
                            }
                        });
                    }
                }]
            }]
        }],
        listeners: {
            render: function () {
                adstore.load();
            }
        }
    });
});